﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Ors.RInterface.Engine.PInvoke
{
    static class R
    {
        [DllImport("R.dll",CallingConvention=CallingConvention.Cdecl)]
        public static extern int R_DefParams(ref  RStart info);
        [DllImport("R.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int R_SetParams( ref RStart info);
        [DllImport("R.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void run_Rmainloop();
        [DllImport("R.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void end_Rmainloop();
        [DllImport("R.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void setup_term_ui();
        [DllImport("R.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void R_SizeFromEnv(ref RStart Rp);
        [DllImport("R.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern string getDLLVersion();
        [DllImport("R.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern string getRUser();
        [DllImport("R.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern string get_R_HOME();
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern void setup_Rmainloop();
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern void R_ReplDLLinit(); 
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern void readconsolecfg(); 
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern void R_set_command_line_arguments(int argc, string[] args);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_mkString(string toConvert);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern void Rf_protect(IntPtr sexp);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern void Rf_unprotect(int popCount);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr STRING_ELT(IntPtr sexp,int n);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr VECTOR_ELT(IntPtr sexp, int n);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern string Rf_translateChar(IntPtr sexp);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern bool Rf_isString(IntPtr sexp);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern bool Rf_isList(IntPtr sexp);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern void Rf_setVar(IntPtr sym,IntPtr val,IntPtr env);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_install(string name);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_allocVector(SEXPTYPE t, int len);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_ScalarReal(double val);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_ScalarInteger(int val);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr SET_VECTOR_ELT(IntPtr vector,int idx,IntPtr val);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr SET_STRING_ELT(IntPtr vector, int idx, IntPtr val);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr REAL(IntPtr vector);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr INTEGER(IntPtr vector);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_mkChar(string s);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_setAttrib(IntPtr target, IntPtr attribute, IntPtr value);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_findVar(IntPtr symbol, IntPtr environment);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern Int32 Rf_length(IntPtr obj);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern bool Rf_isReal(IntPtr obj);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern bool Rf_isInteger(IntPtr obj);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern bool Rf_isLogical(IntPtr obj);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr Rf_getAttrib(IntPtr obj,IntPtr att);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr R_ParseVector(IntPtr code,int n,out RParseStatus status, IntPtr file);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr R_tryEval(IntPtr parsedCode, IntPtr env,out Int32 errorCode);
        [DllImport("R.DLL", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern string R_CHAR(IntPtr sexp);
    }
}
